package com.example.demo;

import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;


import java.util.Arrays;
import java.util.List;

@RestController
public class demo1 {
    @RequestMapping("/r2")
    public String r2(String name,Integer age){
        return "name"+name+"age"+age;
    }
    @RequestMapping("/r3")
    public Student r3(Student student){
        return student;
    }
    @RequestMapping("/r4")
    public String r4(@RequestParam(value="like",required=false) String LIKE){
        return "爱好："+LIKE;
    }
    //接收数组
    @RequestMapping("/r5")
    public String r5(String[] arr){
        return "接收到参数："+ Arrays.toString(arr);
    }
    //接收json
    @RequestMapping("/r6")
    public  String r6(Student student){
        return student.toString();
    }
    @RequestMapping("/r7")
    public  String r7(@RequestBody Student student){
        return student.toString();
    }
    //接收集合
    @RequestMapping("/r8")
    public  String r8(@RequestParam(required = false) List<String> list){
        return "接收的参数"+list;
    }
    //从路径中获取参数
    @RequestMapping("/r9/{name}/{age}")
    public  String r9(@PathVariable("name") String name, @PathVariable("age") Integer age){
        return "name: "+name+"age"+age;
    }
    //上传文件
    @PostMapping("/r10" )
    public void r10(MultipartFile files){
       String filename=files.getOriginalFilename();
       //return "接收到文件："+filename;
    }

    @RequestMapping("/r11")
    @PostMapping
    public String r11Test(@RequestParam(value = "img") MultipartFile img){
        System.out.println("收到请求：");
        return "success";
        //return "接收到文件："+filename;
    }

}

